<? //$this->view('admin/helper/filter/invoices_filter'); ?>
<!--datatables tools-->
<div class="row-fluid">
    <div class="span12">
        <div class="box corner-all">
            <div class="box-header grd-white corner-top">
                <div class="header-control">
                    <a data-box="collapse"><i class="icofont-caret-up"></i></a>
                </div>
                <span><?= lang('label_menu_link_invoicies') ?></span>
            </div>
            <div class="box-body">
                <form action="<?= base_url() ?><?= get_segment(1) ?>/<?= get_segment(2) ?>/all" method="post" style="margin-bottom: 5px;" >
                    <table id="datatablestools" class="table table-hover responsive">
                        <div class="row-fluid">
                            <div class="span6">
                                <div class="DTTT btn-group">
                                    <select class="droop_tool_box" name='doaction'>
                                        <option value=""><?= lang('label_choose_fromlist') ?></option>
                                        <option value="rejected"><?= lang('label_wallet_statues_rejected') ?></option>
                                        <option value="delete"><?= lang('label_delete') ?></option>
                                    </select>
                                    <button class="btn DTTT_button_collection" ><span><?= lang('label_save') ?></span></button></div>
                            </div>
                            <div class="span6">
                                <div class="DTTT btn-group" style="float: left">
                                    <a href="<?= base_url() ?><?= get_segment(1) ?>/<?= get_segment(2) ?>/csv/?<?= uri_get() ?>" class="btn DTTT_button_collection" id="ToolTables_datatablestools_2"><span><?= lang('label_save') ?> scv</span></a></div>
                            </div>
                        </div>
                        <thead>
                            <tr>
                                <th><input type="checkbox" id="checkall" name="all"></th>
                                <th>#</th>
                                <th><?= lang('label_payment_type') ?></th>
                                <th><?= lang('label_confirm_type') ?></th>
                                <th><?= lang('label_store_confirm_type') ?></th>
                                <th><?= lang('label_cash') ?></th>
                                <th><?= lang('label_add_by') ?></th>
                                <th><?= lang('label_created_date') ?></th>
                                <th><?= lang('label_payment_date') ?></th>
                                <th><?= lang('label_confirm_date') ?></th>
                                <th><?= lang('label_tool') ?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?
                            foreach ($result as $value) {
                                if (isset($value->user_add))
                                    $user = get_userdata_with_id($value->user_update, 'id,username')
                                    ?>
                            <tr class="gradeA" <?php if (in_array($value->cancel, array('USER', 'ADMIN'))) { ?>style="background-color: #f7e4e4; text-decoration: line-through" title="<?= lang('label_canceled_by_'.  strtolower($value->cancel)) ?>"<?php } ?>>
                                    <td><input type="checkbox" class="checkall" value="<?= $value->id ?>" name="id[]"></td>
                                    <td >

                                        <a href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/view/<?= $value->inv_num ?>">
                                            <?= strtoupper($value->inv_num) ?>

                                        </a>
                                    </td>
                                    <td>
                                        <? if ($value->payment_status == 'YES') { ?>
                                            <span class="badge green"><?= lang('label_yes') ?></span>
                                        <? } else { ?>
                                            <span class="badge red"><?= lang('label_no') ?></span>
                                        <? } ?>
                                    </td>

                                    <td>
                                        <? if ($value->confirm_status == 'YES') { ?>
                                            <span class="badge green"><?= lang('label_yes') ?></span>
                                        <? } else { ?>
                                            <span class="badge red"><?= lang('label_no') ?></span>
                                        <? } ?>
                                    </td>

                                    <td>
                                        <?
                                        if ($value->itemes == 'YES') {
                                            $itemsaccept = get_items_num_accepted($value->inv_num);
                                            $totalitems = get_items_num($value->inv_num);
                                            $itemsrefused = get_items_num_refuse($value->inv_num);
                                            ?>
                                            <span class="badge green"><?= str_replace('%s', $itemsaccept, lang('label_items_accept')) . '-' . str_replace('%s', $itemsrefused, lang('label_items_refused')) . '/' . $totalitems ?></span>
                                        <? } else { ?>
                                            <span class="badge red"><?= '--' ?></span>
                                        <? } ?>
                                    </td>
                                    <td><span class="badge black-box-dropdown"><?= $value->already_paid . '/' . $value->must_pay ?> </span></td>
                                    <td><a href='<?= base_url() . ADMIN_FOLDER ?>/users/view/<?= $value->user_id ?>'><?= $value->username ?></a></td>
                                    <td><?= timespan($value->create_date, time()) ?></td>
                                    <td><?= timespan($value->payment_date, time()) ?></td>
                                    <td><?= timespan($value->confirm_date, time()) ?></td>

                                    <td class="center">
                                        <div class="btn-group">
                                            <button class="btn  dropdown-toggle" data-toggle="dropdown"><i class="icon-cog"></i>  <?= lang('label_operation') ?> <span class="caret"></span></button>
                                            <ul class="dropdown-menu">
                                                <?php if (in_array($value->cancel, array('USER', 'ADMIN'))) { ?>
                                                <li><a href="javascript:void(0)"> <?= lang('label_canceled_by_'.  strtolower($value->cancel)) ?></a></li>
                                                <?php } else { ?>
                                                    <?
                                                    if ($value->confirm_status == 'NO' && $value->payment_status == 'NO') {
                                                        if ($value->itemes == 'YES') {
                                                            if ($itemsaccept + $itemsrefused < $totalitems) {
                                                                ?>
                                                                <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/senditems/<?= $value->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_send_to_seller') ?></a></li>
                                                            <? } else { ?>
                                                                <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirminv/<?= $value->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_confirm_inv') ?></a></li><? } ?>
                                                        <?php } else { ?>
                                                            <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirminv/<?= $value->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_confirm_inv') ?></a></li><? } ?>
                                                    <?php }
                                                    ?> 
                                                        <? if ($value->payment_status == 'NO') { ?> <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/cancel/<?= $value->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_cancel') ?></a></li><? } ?>
                                                    <? if ($value->confirm_status == 'NO' && $value->payment_status == 'YES') { ?> <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/confirm_pay/<?= $value->inv_num ?>"><i class="icon-check"></i>  <?= lang('label_menu_link_confirm_pay') ?></a></li><? } ?>
                                                    <li><a    href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/edit/<?= $value->inv_num ?>"><i class="icon-edit"></i>  <?= lang('label_edit') ?></a></li>
                                                <?php } ?>
                                                <li><a  class="delete_confirm " href="<?= base_url() . ADMIN_FOLDER ?>/<?= get_segment(2) ?>/delete/<?= $value->inv_num ?>"><i  class="icon-trash"></i> <?= lang('label_delete') ?></a></li>
                                            </ul>
                                        </div>

                                    </td>
                                </tr>
                            <?php } ?>

                        </tbody>
                    </table>
                    <div class="row-fluid">
                        <div class="span6">
                            <div class="DTTT btn-group">
                                <select class="droop_tool_box" name='doaction'>
                                    <option value=""><?= lang('label_choose_fromlist') ?></option>
                                    <option value="rejected"><?= lang('label_wallet_statues_rejected') ?></option>
                                    <option value="delete"><?= lang('label_delete') ?></option>
                                </select>
                                <button class="btn DTTT_button_collection" ><span><?= lang('label_save') ?></span></button></div>
                        </div>
                        <div class="span6">
                            <div class="DTTT btn-group" style="float: left">
                                <a href="<?= base_url() ?><?= get_segment(1) ?>/<?= get_segment(2) ?>/csv/?<?= uri_get() ?>" class="btn DTTT_button_collection" id="ToolTables_datatablestools_2"><span><?= lang('label_save') ?> scv</span></a></div>
                        </div>
                    </div>
                </form>
                <?= $pagination ?>
            </div><!-- /box-body -->
        </div><!-- /box -->
    </div><!-- /span -->
</div><!--/datatables tools-->
